
import { Destroyable, react, JsonValue, track, bind } from "xbsj-xe2/dist-node/xe2-base-utils";
import { MyProjectManager } from '../../MyProjectManager';
import { Building } from "./Building";
import { viewType } from "../dataTypes";
import { cantingBuildData, cantingHighLightData, zonghelouBuildData, zonghelouHighLightData, cantingmap, zongheloumap, zonghelouEffect, cantingEffect } from '../data/buildData';
import { ESUnrealActor, UeESUnrealActor } from "esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main";

export class BuildingCollection extends Destroyable {
    // 餐厅
    public cantingBuilding = new Building(this.myProjectManager)
    // 综合楼
    public zonghelouBuilding = new Building(this.myProjectManager)
    // 阴影
    public shadow: ESUnrealActor | undefined;

    constructor(private myProjectManager: MyProjectManager) {
        super();
        this.init()
    }
    // 初始化
    init() {
        this.cantingBuilding.name = '餐厅'
        this.zonghelouBuilding.name = "综合楼"
        this.cantingBuilding.setData(cantingBuildData, cantingHighLightData, cantingmap, cantingEffect)
        this.zonghelouBuilding.setData(zonghelouBuildData, zonghelouHighLightData, zongheloumap, zonghelouEffect)
        this.shadow = this.myProjectManager.createSceneObject(ESUnrealActor)
        if (!this.shadow) return
        this.shadow.position = [114.042685, 38.06720000000001, 282.9999999997168]
        this.shadow.rotation = [2.354441367550023e-15, 2.582079566300485e-15, -1.5902773592947552e-15]
        this.shadow.actorTag = 'shadow'
    }

    /**
     * 展开/收缩楼宇
     * @param buildingName 
     * @param expand 
     */
    toggleFloor(buildingName: string, expand: boolean, during: number = 2) {
        const promise = new Promise((resolve, reject) => {
            switch (buildingName) {
                case '综合楼':
                    this.zonghelouBuilding.toggleFloor(expand, during).then(() => {
                        resolve('')
                    })
                    break;
                case '餐厅':
                    this.cantingBuilding.toggleFloor(expand, during).then(() => {
                        resolve('')
                    })
                    break;
            }
        })
        return promise
    }
    /**
     * 单层楼层高亮
     * @param floorId 
     */
    setFloorHighLight(floorId: string, status: 'Normal' | 'Warning' | 'none' = 'Normal') {
        this.zonghelouBuilding.setFloorHighLight(floorId, status)
        this.cantingBuilding.setFloorHighLight(floorId, status)
    }
    /**
     * 楼层全部高亮
     * @param buildingName 
     */
    setAllFloorsHighlight(buildingName?: string, show: boolean = true) {
        switch (buildingName) {
            case '综合楼':
                this.zonghelouBuilding.setAllFloorsHighlight(show)
                break;
            case '餐厅':
                this.cantingBuilding.setAllFloorsHighlight(show)
                break;
            default:
                this.zonghelouBuilding.setAllFloorsHighlight(show)
                this.cantingBuilding.setAllFloorsHighlight(show)
                break;
        }
    }
    /**
     * 单层展示楼层
     * @param floorId 
     */
    setFloorVisible(floorId: string, view: viewType) {
        if (floorId == 'all') {
            this.zonghelouBuilding.currentFloor = 'all'
            this.cantingBuilding.currentFloor = 'all'
            this.zonghelouBuilding.toggleFloor(false, 0)
            this.cantingBuilding.toggleFloor(false, 0)
            this.myProjectManager.activeViewer?.flyIn(view.position, view.rotation, 1)
        } else {
            if (floorId.includes('zonghelou')) {
                this.zonghelouBuilding.setFloorVisible(floorId, view)
            }
            if (floorId.includes('canting')) {
                this.cantingBuilding.setFloorVisible(floorId, view)
            }
        }
    }

    /**
     * 显示全部楼层
     * @param buildName 
     */
    setBuildVisible(buildName?: string, show: boolean = true) {
        switch (buildName) {
            case '综合楼':
                this.zonghelouBuilding.setBuildVisible(show)
                break;
            case '餐厅':
                this.cantingBuilding.setBuildVisible(show)
                break;
            default:
                this.zonghelouBuilding.setBuildVisible(show)
                this.cantingBuilding.setBuildVisible(show)
                break;
        }
    }

    /**
     * 设置室内的高度尺寸
     * @param scale 
     */
    setInsideScaleZ(scale: number) {
        this.zonghelouBuilding.setInsideScaleZ(scale)
    }

    /**
     * 设置建筑特效显示/隐藏
     * @param buildName 综合楼/餐厅
     * @param show 
     */
    setBuildingEffect(buildName?: string, show: boolean = true) {
        switch (buildName) {
            case '综合楼':
                this.zonghelouBuilding.setBuildEffect(show)
                break;
            case '餐厅':
                this.cantingBuilding.setBuildEffect(show)
                break;
            default:
                this.zonghelouBuilding.setBuildEffect(show)
                this.cantingBuilding.setBuildEffect(show)
                break;
        }
    }
    /**
     * 设置阴影虚化效果
     * @param show 
     */
    setShadowVisible(show: boolean) {
        if (this.shadow) this.shadow.callFunction('BoundsBlurring', { Switch: show })
    }

}